package tech.heptagram.staff.cas.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lombok.extern.slf4j.Slf4j;

/**
 * 员工管理相关路由配置
 * @author fengqiang
 */
@Controller
@RequestMapping("/system")
@Slf4j
public class PageMappingController {

    @GetMapping("/cas/callback")
    public void casCallBack(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setHeader( "Pragma", "no-cache" );
        response.setDateHeader("Expires", -1);
        response.addHeader( "Cache-Control", "no-cache" );//浏览器和缓存服务器都不应该缓存页面信息
        response.addHeader( "Cache-Control", "no-store" );//请求和响应的信息都不应该被存储在对方的磁盘系统中；
        response.addHeader( "Cache-Control", "must-revalidate" );///于客户机的每次请求，代理服务器必须想服务器验证缓存是否过时；

        log.info("cas 登录成功, 跳转到 /system/cas/callback. ,requestUri: {}", request.getRequestURI());
        String url = request.getRequestURI().replaceAll(request.getServletPath(),"/index");
        log.info("cas 即将跳转url : {}", url);
        response.sendRedirect(url);
    }

    /**
     * 角色管理
     */
    @GetMapping("/role")
    public String role() {
        return "/system/role";
    }
    @GetMapping("/role2")
    public String role2(){
        return "/system/role2";
    }
    /**
     * 菜单管理
     */
    @GetMapping("/menu")
    public String menu() {
        return "/system/menu";
    }

    /**
     * 权限管理
     */
    @GetMapping("/auth")
    public String staff(){
        return "/system/staff";
    }
}
